# Maintainer: Felix Yan <felixonmars@archlinux.org>

pkgname=ruby-ffi-compiler
pkgver=1.0.1
pkgrel=1
pkgdesc='Ruby library for automating compilation of native libraries for use with ffi'
arch=(any)
url='https://github.com/ffi/ffi-compiler'
license=(Apache)
depends=(ruby-ffi ruby-rake)
makedepends=(ruby-rspec ruby-rubygems-tasks)
options=(!emptydirs)
source=(https://github.com/ffi/ffi-compiler/archive/v$pkgver/$pkgname-$pkgver.tar.gz)
sha256sums=('633cdcc7bd6e146523a665872dd5a4db0c0972c661064bdfd60b82f8d221376e')

build() {
  local _gemdir="$(gem env gemdir)"
  cd ffi-compiler-$pkgver
  rake build
  gem install \
    --local \
    --verbose \
    --ignore-dependencies \
    --no-user-install \
    --install-dir "tmp_install/$_gemdir" \
    --bindir "tmp_install/usr/bin" \
    pkg/ffi-compiler-$pkgver.gem
  find "tmp_install/$_gemdir/gems/" \
    -type f \
    \( \
        -iname "*.o" -o \
        -iname "*.c" -o \
        -iname "*.so" -o \
        -iname "*.time" -o \
        -iname "gem.build_complete" -o \
        -iname "Makefile" \
    \) \
    -delete
  rm -r tmp_install/$_gemdir/cache
}

check() {
  local _gemdir="$(gem env gemdir)"
  cd ffi-compiler-$pkgver
  # Should output: Example.example=deadbeef
  # TODO: Disabled because example needs to be built first.
  # GEM_HOME="tmp_install/$_gemdir" ruby <<< 'require "example/example"; puts "Example.example=#{Example.example.to_s(16)}"'
}

package() {
  cd ffi-compiler-$pkgver
  cp -a tmp_install/* "$pkgdir"/
}
